/*
 * 文 件 名 : FriendTabActivity.java
 * 版    权 : China Machi.Co.,Ltd.Copyright 2009-2011.All rights reserved
 * 描    述 : <描述>
 * 修 改 人 : lixg
 * 修改时间 : 2012-9-18
 * 跟踪单号 : <跟踪单号>
 * 修改单号 : <修改单号>
 * 修改内容 : <修改内容>
 */
package com.fire8.dolphin.ui.chat;

import android.app.ActivityGroup;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;

import com.fire8.dolphin.ui.R;

/**
 * 心理咨询页面
 * 左边为会话开表，记录与谁联系过
 * 右边为在线咨询师列表，显示当前谁在线
 * @author  lixg
 * @version [版本号,2012-9-18]
 * @see     [相关类/方法]
 * @since   [产品/模块]
 */
public class FriendTabActivity extends ActivityGroup
{
    private Button btnRight;
    private LinearLayout container = null;
    private Button btnFriend=null;
    private Button btnUserList=null;
    private View lvLine;
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.friend_tab);
        container = (LinearLayout) findViewById(R.id.containerBody);
        container.addView(getLocalActivityManager().startActivity(
                "Module1",
                new Intent(FriendTabActivity.this, FriendActivity.class)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .getDecorView());
        
        //TextView tvTitle = (TextView)findViewById(R.id.tv_bar_title);
        //tvTitle.setText("消息与会话");
        lvLine = findViewById(R.id.v_line1);
        btnRight = (Button)findViewById(R.id.title_bt_right);
        btnRight.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //弹出查询窗口
                
            }
        });
        
        btnFriend = (RadioButton)findViewById(R.id.radio_button0);
        btnFriend.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                container.removeAllViews();
                container.addView(getLocalActivityManager().startActivity(
                        "Module1",
                        new Intent(FriendTabActivity.this, FriendActivity.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView());
                lineAnimLeft();//将下面的线条向左移
                btnFriend.setTextColor(getResources().getColor(R.color.blue));
                btnUserList.setTextColor(getResources().getColor(R.color.font_gray));
            }
        });
        
        btnUserList = (RadioButton)findViewById(R.id.radio_button1);
        btnUserList.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                container.removeAllViews();
                container.addView(getLocalActivityManager().startActivity(
                        "Module2",
                        new Intent(FriendTabActivity.this, UserListActivity.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView());
                lineAnimRight();//将下面的线条向右移
                btnUserList.setTextColor(getResources().getColor(R.color.blue));
                btnFriend.setTextColor(getResources().getColor(R.color.font_gray));
            }
        });
        
        //在按钮下画一条线
        
    }
    
    private void lineAnimLeft()
    {
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        int screenWidth = wm.getDefaultDisplay().getWidth();//屏幕宽度
        int width =Math.abs(screenWidth/2);//线条宽度
        int[] location = new int[2];  
        lvLine.getLocationOnScreen(location);  
        int x = location[0];  
        int y = location[1];  
        TranslateAnimation anim = new TranslateAnimation(width,0,0,0);
        //lvLine.setAnimation(anim);
        anim.setDuration(500);
        anim.setFillAfter(true);
        //anim.start();
        lvLine.startAnimation(anim);
    }
    private void lineAnimRight()
    {
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        int screenWidth = wm.getDefaultDisplay().getWidth();//屏幕宽度
        int width =Math.abs(screenWidth/2);//线条宽度
        int[] location = new int[2];  
        lvLine.getLocationOnScreen(location);  
        int x = location[0];  
        int y = location[1];  
        TranslateAnimation anim = new TranslateAnimation(0f,width,0,0);
        
        anim.setDuration(500);
        anim.setFillAfter(true);
        //anim.start();
        lvLine.startAnimation(anim);
    }
}
